package com.jvyou.common.auth;

import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.collection.CollUtil;
import com.jvyou.common.redis.RedisCache;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 鉴权
 *
 * @author dhb
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class StpInterfaceImpl implements StpInterface {

    private final RedisCache redisCache;

    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        log.info("获取权限列表:{}", StpUtil.getExtra(SaTokenConfigure.JWT_PERMISSION_LIST_KEY));
        return (List<String>) StpUtil.getExtra(SaTokenConfigure.JWT_PERMISSION_LIST_KEY);
    }

    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        String role = (String) StpUtil.getExtra(SaTokenConfigure.JWT_CURRENT_ROLE_KEY);
        return CollUtil.newArrayList(role);
    }
}
